import { history } from "./base.js";
function getHash() {
  return window.location.hash.slice(1); // 注意 #/
}
class HashHistory extends history {
  constructor(router) {
    super(router);
    this.router = router;

    // 确保路径是一个hash模式
    ensureSlash();
  }

  // 获取当前的路径
  getCurrentLocation() {
    return getHash();
  }
  // 监听
  setUpLister() {
    window.addEventListener("hashchange", () => {
      //跳转到最新的路径
      this.transitionsTo(this.getCurrentLocation());
    });
  }
}
function ensureSlash() {
  if (window.location.hash) {
    return;
  }
  window.location.hash = "/";
}
export { HashHistory };
